from django.db import models

class Fans(models.Model):
    """
    粉丝表
    用户(关系属性)、 粉丝(关系属性)、 是否互相关注 、 关注时间、互关时间

    """
    user = models.ForeignKey(to="auth.User", verbose_name="用户", on_delete=models.CASCADE, related_name="fans_list")

    fans = models.ForeignKey(to="auth.User", verbose_name="粉丝", on_delete=models.CASCADE)

    follow_time = models.DateTimeField(verbose_name="关注时间", db_comment="关注时间", auto_now_add=True)

    is_mutual = models.BooleanField(verbose_name="是否互相关注", db_comment="是否互相关注", default=False)

    mutual_time = models.DateTimeField(verbose_name="互关时间", db_comment="互关时间", null=True, blank=True)

    class Meta:
        db_table = "tb_fans"
        unique_together = ("user", "fans")


class Advice(models.Model):
    """
    公告表
	标题、 内容、 发布时间、状态、录入时间、修改时间、是否删除
    """
    title = models.CharField(max_length=128, verbose_name="标题", db_comment="标题")

    content = models.TextField(verbose_name="内容", db_comment="内容")

    publish_time = models.DateTimeField(verbose_name="发布时间", db_comment="发布时间")

    state = models.BooleanField(verbose_name="状态", db_comment="状态", default=False)

    create_time = models.DateTimeField(verbose_name="录入时间", db_comment="录入时间", auto_now_add=True)

    update_time = models.DateTimeField(verbose_name="修改时间", db_comment="修改时间")

    is_delete = models.BooleanField(verbose_name="是否删除", db_comment="是否删除", default=False)

    class Meta:
        db_table = "tb_advice"

class AdviceRead(models.Model):
    """
    公告阅读表
    公告(关系属性)、 用户(关系属性)、 阅读时间
    """
    advice = models.ForeignKey(to=Advice, verbose_name="公告", on_delete=models.CASCADE)

    user = models.ForeignKey(to="auth.User", verbose_name="用户", on_delete=models.CASCADE)

    read_time = models.DateTimeField(verbose_name="阅读时间", db_comment="阅读时间", auto_now_add=True)

    class Meta:
        db_table = "tb_advice_read"
        unique_together = ("advice", "user")

class Notify(models.Model):
    """
    通知表
    通知类型 、 通知内容、用户(关系属性)、 通知时间、 是否已读、 读取时间 、
    """
    type = models.CharField(max_length=64, verbose_name="通知类型", db_comment="通知类型")

    user = models.ForeignKey(to="auth.User", verbose_name="用户", on_delete=models.CASCADE)

    content = models.TextField(verbose_name="内容", db_comment="内容")

    publish_time = models.DateTimeField(verbose_name="发布时间", db_comment="发布时间")

    state = models.BooleanField(verbose_name="状态", db_comment="状态", default=False)

    create_time = models.DateTimeField(verbose_name="录入时间", db_comment="录入时间", auto_now_add=True)

    class Meta:
        db_table = "tb_notify"



class Letter(models.Model):
    """
    私信表
    发送者(关系属性)、 接收者(关系属性)、 内容、 发送时间、 是否已读、 读取时间
    """
    sender = models.ForeignKey(to="auth.User", verbose_name="发送者", on_delete=models.CASCADE, related_name="sender")

    receiver = models.ForeignKey(to="auth.User", verbose_name="接收者", on_delete=models.CASCADE, related_name="receiver")

    content = models.TextField(verbose_name="内容", db_comment="内容")

    send_time = models.DateTimeField(verbose_name="发送时间", db_comment="发送时间", auto_now_add=True)

    is_read = models.BooleanField(verbose_name="是否已读", db_comment="是否已读", default=False)

    read_time = models.DateTimeField(verbose_name="读取时间", db_comment="读取时间", null=True, blank=True)

    class Meta:
        db_table = "tb_letter"


class Swiper(models.Model):
    """
    轮播图表
    图片地址 、超链接地址 、是否启用 、是轮播图还是广告、  录入时间、是否删除
    """
    image = models.ImageField(upload_to="swiper/", verbose_name="图片", db_comment="图片")

    link = models.CharField(max_length=128, verbose_name="跳转链接", db_comment="跳转链接")

    create_time = models.DateTimeField(verbose_name="录入时间", db_comment="录入时间", auto_now_add=True)

    state = models.BooleanField(verbose_name="状态", db_comment="状态", default=False)

    type = models.CharField(max_length=10, verbose_name="类型",
                            choices=(('0', '轮播图'), ('1', '广告')),
                            db_comment="类型", default='0')

    is_delete = models.BooleanField(verbose_name="是否删除", db_comment="是否删除", default=False)

    class Meta:
        db_table = "tb_swiper"